import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_getx_project/pages/home/home_state.dart';
import 'package:get/get.dart';

/// Created by XieXin on 2022/8/23.
/// 业务逻辑处理
class HomeController extends GetxController {
  HomeState state = HomeState();
  late TextEditingController mobileController;
  late TextEditingController passwordController;
  late FocusNode nodeText1;
  late FocusNode nodeText2;

  @override
  void onInit() {
    super.onInit();
    mobileController = TextEditingController();
    passwordController = TextEditingController();
    nodeText1 = FocusNode();
    nodeText2 = FocusNode();
    mobileController.addListener(_verify);
    passwordController.addListener(_verify);
  }


  void _verify() {
    state.username = mobileController.text;
    state.password = passwordController.text;
    bool isClick = false;
    if (state.username.isNotEmpty &&
        state.username.length == 11 &&
        state.password.isNotEmpty &&
        state.password.length >= 6) {
      isClick = true;
    } else {
      isClick = false;
    }

    /// 状态不一样在刷新，避免重复不必要的setState
    if (state.isClickLogin != isClick) {
      state.isClickLogin = isClick;
      update();
    }
  }

  @override
  void onClose() {
    LogUtil.v("====================>onClose");
    super.onClose();
  }
}
